package com.wisely.xxboot.domain;

import com.wisely.xxboot.dao.RedisPerson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2017</p>
 * <p>Company: 中视数讯</p>
 * <p>Site: www.digi-zones.com</p>
 *
 * @author shengping
 * @version 1.0
 * @date 2017/7/3
 */

@Repository
public class RedisPersonDao {
    @Autowired
    StringRedisTemplate stringRedisTemplate; //1 springboot已经为我们配置stringredistemplate 此处可以直接注入

    @Resource(name = "stringRedisTemplate") //3 可以使用resource注解执行stringredistemplate可注入简单点字符串进行操作
    ValueOperations<String, String> valueOperationsstr;

    @Autowired
    RedisTemplate<Object, Object> redisTemplate;  //2 springboot已经为我们配置redistemplate 此处可以直接注入

    @Resource(name = "redisTemplate") //4 以使用resource注解执行redistemplate可注入简单点字符串进行操作
    ValueOperations<Object, Object> valueOperations;

    public void stringRedisTemplateDemo(){ //5 通过set方法，存贮字符串类型
        valueOperationsstr.set("xx", "yy");
    }
    public void save(RedisPerson redisPerson){
        valueOperations.set(redisPerson.getId(),redisPerson); //6 通过set 贮存对象类型
    }

    public String getString(){
        return valueOperationsstr.get("xx"); //7 通过get方法获得字符串
    }

    public RedisPerson getPerson(){
        return (RedisPerson) valueOperations.get("1");  //8 通过get获得对象
    }

}
